package stage
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.utils.setTimeout;
	
	public class NimbusSprite extends Sprite
	{
		private var smallSprite:DisplayObject;
		private var bigSprite:DisplayObject;
		private var icon:DisplayObject;
		public function NimbusSprite(bigSprite:DisplayObject,smallSprite:DisplayObject,icon:DisplayObject)
		{
			this.smallSprite=smallSprite;
			this.bigSprite=bigSprite;
			this.icon=icon;
			//add icon, nimbus and set the positions
			this.addChild(bigSprite);
			trace("nimsprite.w"+this.width+" nimsprite.h"+this.height);
			this.addChild(smallSprite);
			smallSprite.x=bigSprite.width/2-smallSprite.width/2;
			smallSprite.y=bigSprite.height/2-smallSprite.height/2;
			this.addChild(icon);
			icon.x=bigSprite.width/2-icon.width/2;
			icon.y=bigSprite.height/2-icon.height/2;
			this.smallSprite.visible=false;
			this.bigSprite.visible=false;
		}
		
		public var isPlayingEffect:Boolean=false;
		
		public function effectNimbus():void
		{
			if(!isPlayingEffect)
			{
				isPlayingEffect=true;
				smallSprite.visible=true;
				setTimeout(function():void
				{
					smallSprite.visible=false;
					bigSprite.visible=true;
				},500);
				setTimeout(function():void
				{
					smallSprite.visible=false;
					bigSprite.visible=false;
					isPlayingEffect=false;
				},1000);
			}		
		}
		
		
		public static function createNimbusSprite(type:int):NimbusSprite
		{
			var ImageProtypeClass:Class=ResourceManager.getImageClass(type);
			var imageInstance:DisplayObject=new ImageProtypeClass() as DisplayObject;
			
			var BigNimbusProypeClass:Class=ResourceManager.getBigNumClass(type);
			var bignimbusInstance:DisplayObject=new BigNimbusProypeClass() as DisplayObject;
			
			var SmallNimbusProtypeClass:Class=ResourceManager.getSmallNumClass(type);
			var smallnimbusInstance:DisplayObject=new SmallNimbusProtypeClass() as DisplayObject;
			
			var nimbusInstance:NimbusSprite=new NimbusSprite(bignimbusInstance,smallnimbusInstance,imageInstance);
			return nimbusInstance;
		}
		
		
	}
}